Skip to content

fix: migrate SharedTopicClient to raw topic API - #1

Open
Jiu-xiao wants to merge 1 commit into
masterfrom
codex/sharedtopicclient-raw-topic-20260630
Open

fix: migrate SharedTopicClient to raw topic API#1
Jiu-xiao wants to merge 1 commit into
masterfrom
codex/sharedtopicclient-raw-topic-20260630

Conversation

@Jiu-xiao

@Jiu-xiao Jiu-xiao commented Jun 30, 2026

Copy link
Copy Markdown
Member

Summary

  • migrate SharedTopicClient to the new libxr raw topic callback and Topic::PackRaw(...) API
  • replace removed LockFreeQueue / LockFreePool usage with MPMCQueue
  • use public Topic(topic).PayloadSize() instead of old internal topic block fields
  • keep runtime arbitrary-topic forwarding by storing the TopicHandle in callback context
  • update README to describe the current queue and raw packet path

Dependency

Requires libxr master at or after 5728458 (feat(message): add raw topic callback and packet API).

Validation

  • Ubuntu24 /tmp/libxr_raw_topic_sharedtopic_smoke2_20260630T010357Z: patched libxr + patched SharedTopicClient constructor/publish smoke passed
  • Ubuntu24 /tmp/libxr_raw_topic_module_smoke2_20260630T010424Z/smoke_raw_topic_20260630T010430Z: dependency-closure smoke result 48 PASS / 8 FAIL; xrobot-org/SharedTopicClient passed

Summary by Sourcery

Align SharedTopicClient with the latest libxr raw topic and queue APIs while preserving multi-topic UART forwarding behavior.

Bug Fixes:

  • Migrate SharedTopicClient to libxr raw topic callback and PackRaw APIs for topic forwarding.

Enhancements:

  • Replace deprecated lock-free queue/pool structures with MPMCQueue-based slot and packet management.
  • Use public Topic payload size and handle-based packing to support arbitrary topics at runtime.

Documentation:

  • Update README to reflect MPMCQueue usage, raw packet path, and updated timestamp packing API.

@sourcery-ai

sourcery-ai Bot commented Jun 30, 2026

Copy link
Copy Markdown

Reviewer's Guide

Migrates SharedTopicClient to libxr’s new raw topic callback and MPMCQueue-based packet buffering, updating topic packing to use Topic::PackRaw and modern Topic APIs while aligning the README with the new queueing and raw packet path behavior.

Sequence diagram for raw topic callback and MPMCQueue-based forwarding

sequenceDiagram
    actor TopicPublisher
    participant LibXR_Topic
    participant SharedTopicClient
    participant MPMCQueue_ready as MPMCQueue_ready_packets
    participant UART_WritePort

    TopicPublisher->>LibXR_Topic: Publish
    LibXR_Topic->>SharedTopicClient: raw_topic_callback(timestamp, ConstRawData)
    SharedTopicClient->>SharedTopicClient: OnTopic(in_isr, CallbackInfo, timestamp, ConstRawData)
    SharedTopicClient->>LibXR_Topic: Topic(info.topic).PackRaw(ConstRawData, PacketSlot.buffer, timestamp)

    alt [PackRaw == ErrorCode::OK]
        SharedTopicClient->>MPMCQueue_ready: Push(ReadyPacket)
        alt [Push == ErrorCode::OK]
            SharedTopicClient->>SharedTopicClient: TxService(in_isr)
            SharedTopicClient->>MPMCQueue_ready: Pop(ReadyPacket)
            alt [Pop == ErrorCode::OK]
                SharedTopicClient->>UART_WritePort: [enqueue packet to WritePort]
            else [Pop != ErrorCode::OK]
                SharedTopicClient->>SharedTopicClient: ReturnFreeSlot(slot_index)
            end
        else [Push != ErrorCode::OK]
            SharedTopicClient->>SharedTopicClient: ReturnFreeSlot(slot_index)
        end
    else [PackRaw != ErrorCode::OK]
        SharedTopicClient->>SharedTopicClient: ReturnFreeSlot(slot_index)
    end
Loading

File-Level Changes

Change Details Files
Switch SharedTopicClient from legacy topic internals and lock-free queues to the new raw topic callback API and MPMCQueue-based buffering.
  • Replace LockFreeQueue/LockFreePool usage with MPMCQueue<uint32_t> and MPMCQueue, adjusting constructor initialization and queue operations from Get/Put to Pop/Push.
  • Update callback wiring to use LibXR::Topic::Callback::Create with a CallbackInfo that stores a TopicHandle instead of a CRC, and adjust callback signatures to pass ConstRawData by const reference.
  • Replace direct access to topic internal fields and Topic::PackData with Topic(topic_handle).PayloadSize() and Topic(topic_handle).PackRaw(...) for computing packet size and packing raw data, including error checking.
SharedTopicClient.hpp
Align SharedTopicClient documentation with the new queue implementation and raw packet packing path.
  • Document the use of MPMCQueue for free-slot and ready-packet management, including capacity constraints and FIFO behavior.
  • Update the description of TxService failure handling to reflect that packets are dropped and slots freed instead of re-queued in a pool.
  • Update timestamp handling documentation to reference Topic(topic_handle).PackRaw(...) instead of Topic::PackData(...) for serial packet writing.
README.md

Tips and commands

Interacting with Sourcery

  • Trigger a new review: Comment @sourcery-ai review on the pull request.
  • Continue discussions: Reply directly to Sourcery's review comments.
  • Generate a GitHub issue from a review comment: Ask Sourcery to create an
    issue from a review comment by replying to it. You can also reply to a
    review comment with @sourcery-ai issue to create an issue from it.
  • Generate a pull request title: Write @sourcery-ai anywhere in the pull
    request title to generate a title at any time. You can also comment
    @sourcery-ai title on the pull request to (re-)generate the title at any time.
  • Generate a pull request summary: Write @sourcery-ai summary anywhere in
    the pull request body to generate a PR summary at any time exactly where you
    want it. You can also comment @sourcery-ai summary on the pull request to
    (re-)generate the summary at any time.
  • Generate reviewer's guide: Comment @sourcery-ai guide on the pull
    request to (re-)generate the reviewer's guide at any time.
  • Resolve all Sourcery comments: Comment @sourcery-ai resolve on the
    pull request to resolve all Sourcery comments. Useful if you've already
    addressed all the comments and don't want to see them anymore.
  • Dismiss all Sourcery reviews: Comment @sourcery-ai dismiss on the pull
    request to dismiss all existing Sourcery reviews. Especially useful if you
    want to start fresh with a new review - don't forget to comment
    @sourcery-ai review to trigger a new review!

Customizing Your Experience

Access your dashboard to:

  • Enable or disable review features such as the Sourcery-generated pull request
    summary, the reviewer's guide, and others.
  • Change the review language.
  • Add, remove or edit custom review instructions.
  • Adjust other review settings.

Getting Help

@sourcery-ai sourcery-ai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hey - I've reviewed your changes and they look great!


Sourcery is free for open source - if you like our reviews please consider sharing them ✨
Help me be more useful! Please click 👍 or 👎 on each comment and I'll use the feedback to improve your reviews.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant